/* GUI CONVERTED from wowoisb.p (converter v1.75) Sat Aug 12 16:38:10 2000 */
/* wowoisb.p - WORK ORDER ISSUE WITH SERIAL NUMBERS SUBROUTINE          */
/* Copyright 1986-2002 QAD Inc., Carpinteria, CA, USA.                  */
/* All rights reserved worldwide.  This is an unpublished work.         */
/*F0PN*/ /*V8:ConvertMode=Maintenance                                   */
/*K1Q4*/ /*V8:RunMode=Character,Windows                                 */
/* REVISION: 7.3      LAST MODIFIED: 09/23/94   by: emb  *GM78*/
/* REVISION: 7.3      LAST MODIFIED: 11/08/94   by: rwl  *GO34*/
/* REVISION: 7.5      LAST MODIFIED: 11/21/94   by: taf  *J038*/
/* REVISION: 8.6      LAST MODIFIED: 05/20/98   by: *K1Q4* Alfred Tan   */
/* REVISION: 9.1      LAST MODIFIED: 08/12/00   by: *N0KC* myb          */
/* REVISION: 9.1      LAST MODIFIED: 09/09/02   by: *N1T7* Rajesh Kini  */
/* This subroutine extracted from wowois.p due to action code segment problems
   during compilation under version 7 Progress.  Patches in effect in wowois.p
   (and included here but not noted specifically in the code) are 'FP55, G223,
   G527, G656, G872 and GM61'. */
     {mfdeclre.i} /*GUI moved to top.*/

     define input parameter wo_recno as recid.
     define input parameter wo-op as integer.
     define input parameter fill_all as logical.
     define input parameter fill_pick as logical.
     define output parameter undo-all as logical.
     define buffer woddet for wod_det.
     define variable tot_lad_all like lad_qty_all.
     define variable ladqtychg like lad_qty_all.
     define variable msg-counter as integer no-undo.
     
/*GUI moved mfdeclre/mfdtitle.*/
     undo-all = yes.
     mainloop:
     do:
           {gplock.i
           &file-name=wo_mstr
           &find-criteria="recid(wo_mstr) = wo_recno"
           &exit-allowed=yes
           &record-id=recno}
           if keyfunction(lastkey) = "end-error" then do:
          leave mainloop.
           end.
/*N1T7**   for each sr_wkfl exclusive where sr_userid = mfguser: */
/*N1T7*/   for each sr_wkfl
/*N1T7*/      where sr_userid = mfguser
/*N1T7*/   exclusive-lock:

          delete sr_wkfl.
           end.
           for each wod_det no-lock where wod_lot = wo_lot
           and (wod_op = wo-op or wo-op = 0):
           	
/*GUI*/ if global-beam-me-up then undo, leave.
          find pt_mstr where pt_part = wod_part no-lock no-error.
          do for woddet:
/*N1T7**     find woddet exclusive where recid(woddet) = recid(wod_det). */
/*N1T7*/     find woddet
/*N1T7*/        where recid(woddet) = recid(wod_det)
/*N1T7*/     exclusive-lock.
             wod_qty_chg = 0.
             if wod_qty_req >= 0
             then wod_bo_chg = max(0, wod_qty_req
                     - max(wod_qty_iss,0) - wod_qty_chg).
             else wod_bo_chg = min(0, wod_qty_req
                     - min(wod_qty_iss,0) - wod_qty_chg).
             if fill_all or fill_pick then do:
            tot_lad_all = 0.
            for each lad_det where lad_dataset = "wod_det"
            and lad_nbr = wod_lot and lad_line = string(wod_op)
            and lad_part = wod_part:
            
/*GUI*/ if global-beam-me-up then undo, leave.

               define variable rejected like mfc_logical.
/*J038* ADD BLANKS FOR TRNBR AND TRLINE AS INPUTS TO ICEDIT2.P               */
               {gprun.i ""icedit2.p""
                  "(""ISS-WO"",
                    lad_site,
                lad_loc,
                wod_part,
                lad_lot,
                lad_ref,
                    (if fill_all then lad_qty_all else 0)
                      + (if fill_pick then lad_qty_pick else 0),
                    pt_um,
                """",
                """",
                output rejected)"}
                
/*GUI*/ if global-beam-me-up then undo, leave.

               if rejected then do on endkey undo, retry:
/*N1T7**          {mfmsg02.i 161 2 wod_part} */

/*N1T7*/          /*{pxmsg.i
                      &MSGNUM=161
                      &ERRORLEVEL=2
                      &MSGARG1=wod_part}
                      &PAUSEAFTER=TRUE}*/
                  if wod_qty_req >= 0
                  then wod_bo_chg = max(0, wod_qty_req
                        - max(wod_qty_iss,0) - wod_qty_chg).
                  else wod_bo_chg = min(0, wod_qty_req
                        - min(wod_qty_iss,0) - wod_qty_chg).
                  next.
               end.
               ladqtychg = 0.
               if fill_all then do:
                  ladqtychg = lad_qty_all.
                  wod_qty_chg = wod_qty_chg + lad_qty_all.
                  tot_lad_all = tot_lad_all + lad_qty_all.
               end.
               if fill_pick then do:
                  ladqtychg = ladqtychg + lad_qty_pick.
                  wod_qty_chg = wod_qty_chg + lad_qty_pick.
               end.
               if ladqtychg <> 0 then do:
                  create sr_wkfl.
                  assign sr_userid = mfguser
               sr_lineid = string(wod_part,"x(18)") + string(wod_op)
                  sr_site = lad_site
                  sr_loc = lad_loc
                  sr_lotser = lad_lot
                  sr_ref = lad_ref
                  sr_qty = ladqtychg.
/*GO34*                       recno = recid(sr_wkfl). */
/*GO34*/                      if recid(sr_wkfl) = -1 then .
               end.
            end.
            
/*GUI*/ if global-beam-me-up then undo, leave.

            if fill_all and tot_lad_all <> wod_qty_all then do:
             find pt_mstr where pt_part = wod_part no-lock no-error.
               if not available pt_mstr or pt_lot_ser = "" then do:
                  find sr_wkfl where sr_userid = mfguser
                  and sr_lineid = string(wod_part,"x(18)")
                  + string(wod_op)
                  and sr_site = wod_site
                  and sr_loc = wod_loc and sr_lotser = ""
                  and sr_ref = "" no-error.
/*J038* ADD BLANKS FOR TRNBR AND TRLINE AS INPUTS TO ICEDIT2.P               */
                  {gprun.i ""icedit2.p""
                  "(input ""ISS-WO"",
                        input wod_site,
                    input wod_loc,
                    input wod_part,
                        input """",
                    input """",
                        input ((wod_qty_all - tot_lad_all)
                     + if available sr_wkfl then sr_qty else 0),
                        input if available pt_mstr
                        then pt_um else """",
                    """",
                    """",
                        output rejected)"}
/*GUI*/ if global-beam-me-up then undo, leave.

                  if rejected then do on endkey undo, retry:
/*N1T7**          {mfmsg02.i 161 2 wod_part} */

/*N1T7*/          /*{pxmsg.i
                      &MSGNUM=161
                      &ERRORLEVEL=2
                      &MSGARG1=wod_part}
                      &PAUSEAFTER=TRUE}*/
                 if wod_qty_req >= 0
                 then wod_bo_chg = max(0, wod_qty_req
                        - max(wod_qty_iss,0) - wod_qty_chg).
                 else wod_bo_chg = min(0, wod_qty_req
                        - min(wod_qty_iss,0) - wod_qty_chg).
                 next.
                  end.
                  if not available sr_wkfl then do:
                 create sr_wkfl.
                 assign
                 sr_userid = mfguser
                 sr_lineid = string(wod_part,"x(18)")
                   + string(wod_op)
                 sr_site = wod_site
                 sr_loc = wod_loc
                 sr_lotser = ""
                 sr_ref = "".
/*GO34*                          recno = recid(sr_wkfl). */
/*GO34*/                         if recid(sr_wkfl) = -1 then .
                  end.
                  sr_qty = sr_qty + (wod_qty_all - tot_lad_all).
                  wod_qty_chg = wod_qty_chg
                      + (wod_qty_all - tot_lad_all).
               end.
            end.
             end.
             if wod_qty_req >= 0
             then wod_bo_chg = max(0, wod_qty_req
                     - max(wod_qty_iss,0) - wod_qty_chg).
             else wod_bo_chg = min(0, wod_qty_req
                     - min(wod_qty_iss,0) - wod_qty_chg).
          end. /* do for woddet */
           end. /*for each wod_det*/
/*GUI*/ if global-beam-me-up then undo, leave.

        undo-all = no.
     end.
